package com.ruoyi.web.controller.pet;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pet.domain.PetMedicine;
import com.ruoyi.pet.service.IPetMedicineService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 药品库存信息Controller
 * 
 * @author 木有枝
 * @date 2025-04-13
 */
@RestController
@RequestMapping("/pet/medicine")
public class PetMedicineController extends BaseController
{
    @Autowired
    private IPetMedicineService petMedicineService;

    /**
     * 查询药品库存信息列表
     */
    @PreAuthorize("@ss.hasPermi('pet:medicine:list')")
    @GetMapping("/list")
    public TableDataInfo list(PetMedicine petMedicine)
    {
        startPage();
        List<PetMedicine> list = petMedicineService.selectPetMedicineList(petMedicine);
        return getDataTable(list);
    }

    /**
     * 导出药品库存信息列表
     */
    @PreAuthorize("@ss.hasPermi('pet:medicine:export')")
    @Log(title = "药品库存信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PetMedicine petMedicine)
    {
        List<PetMedicine> list = petMedicineService.selectPetMedicineList(petMedicine);
        ExcelUtil<PetMedicine> util = new ExcelUtil<PetMedicine>(PetMedicine.class);
        util.exportExcel(response, list, "药品库存信息数据");
    }

    /**
     * 获取药品库存信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('pet:medicine:query')")
    @GetMapping(value = "/{medicineId}")
    public AjaxResult getInfo(@PathVariable("medicineId") Long medicineId)
    {
        return success(petMedicineService.selectPetMedicineByMedicineId(medicineId));
    }

    /**
     * 新增药品库存信息
     */
    @PreAuthorize("@ss.hasPermi('pet:medicine:add')")
    @Log(title = "药品库存信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PetMedicine petMedicine)
    {
        return toAjax(petMedicineService.insertPetMedicine(petMedicine));
    }

    /**
     * 修改药品库存信息
     */
    @PreAuthorize("@ss.hasPermi('pet:medicine:edit')")
    @Log(title = "药品库存信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PetMedicine petMedicine)
    {
        return toAjax(petMedicineService.updatePetMedicine(petMedicine));
    }

    /**
     * 删除药品库存信息
     */
    @PreAuthorize("@ss.hasPermi('pet:medicine:remove')")
    @Log(title = "药品库存信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{medicineIds}")
    public AjaxResult remove(@PathVariable Long[] medicineIds)
    {
        return toAjax(petMedicineService.deletePetMedicineByMedicineIds(medicineIds));
    }
}
